package ru.voice2blog.engine;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.voice2blog.common.exception.InitException;

import java.util.Properties;


/**
 * User: itimofeev
 * Date: 25.04.11
 * Time: 17:34
 */
public class FrameworkManager {

    private static final Logger log = LoggerFactory.getLogger(FrameworkManager.class);


    private static final String PROPERTIES_FILE = "prop.properties";


    public static V2BFramework getInstance() {
        log.info("V2BFramework initializations started.");

        V2BFramework fw = new V2BFramework();

        try {
            initInstanceFromProperties(fw);
            log.info("V2BFramework initializations completed.");
        } catch (Exception e) {
            log.error("Unable to initialize framework instance.", e);
            fw = null;
            System.exit(0);
        }
        return fw;
    }

    private static void initInstanceFromProperties(V2BFramework fw) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InitException {
        Properties mainProperties = ModuleFactory.loadProperties(PROPERTIES_FILE);

        fw.uploader = ModuleFactory.getDataUploader(mainProperties);
        fw.publisher = ModuleFactory.getPublisher(mainProperties);
    }

}
